//package com.zxiw.zxedu.recyclerview.divider
//
//import android.content.Context
//import android.content.res.Resources
//import android.graphics.Canvas
//import android.graphics.Paint
//import android.graphics.drawable.Drawable
//import androidx.recyclerview.widget.RecyclerView
//import com.zxiw.zxedu.recyclerview.XRecyclerView
//import jdk.javadoc.internal.doclets.toolkit.util.DocPath.parent
//
//
//
//
//
///**
// * @author zhangxiaoming
// * @date 2023/8/17
// * @description
// */
//abstract class FlexibleDividerDecoration(builder: Builder) : RecyclerView.ItemDecoration() {
//
//    protected var mDividerType = DividerType.DRAWABLE
//    protected var mVisibilityProvider: VisibilityProvider? = null
//    protected var mPaintProvider: PaintProvider? = null
//    protected var mColorProvider: ColorProvider? = null
//    protected var mDrawableProvider: DrawableProvider? = null
//    protected var mSizeProvider: SizeProvider? = null
//    protected var mShowLastDivider = false
//    protected var mPositionInsideItem = false
//    private var mPaint: Paint? = null
//    private var mStartSkipCount = -1 //跳过开头的几个分割线不显示 默认不处理
//
//    private var mEndSkipCount = -1 //跳过结尾的介个分割线不显示 默认不处理
//
//
//    companion object {
//        private const val DEFAULT_SIZE = 2
//        private val ATTRS = intArrayOf(android.R.attr.listDivider)
//    }
//
//    enum class DividerType {
//        DRAWABLE, PAINT, COLOR
//    }
//
//    init {
//        if (builder.mPaintProvider != null) {
//            mDividerType = DividerType.PAINT
//            mPaintProvider = builder.mPaintProvider
//        } else if (builder.mColorProvider != null) {
//            mDividerType = DividerType.COLOR
//            mColorProvider = builder.mColorProvider
//            mPaint = Paint()
//            setSizeProvider(builder)
//        } else {
//            mDividerType = DividerType.DRAWABLE
//            mDrawableProvider = if (builder.mDrawableProvider == null) {
//                val a = builder.mContext.obtainStyledAttributes(ATTRS)
//                val divider = a.getDrawable(0)
//                a.recycle()
//                object : DrawableProvider {
//                    override fun drawableProvider(position: Int, parent: RecyclerView): Drawable {
//                        return divider!!
//                    }
//                }
//            } else {
//                builder.mDrawableProvider
//            }
//            mSizeProvider = builder.mSizeProvider
//        }
//
//        mVisibilityProvider = builder.mVisibilityProvider
//        mShowLastDivider = builder.mShowLastDivider
//        mPositionInsideItem = builder.mPositionInsideItem
//        mStartSkipCount = builder.mStartSkipCount
//        mEndSkipCount = builder.mEndSkipCount
//    }
//
//    private fun setSizeProvider(builder: Builder) {
//        mSizeProvider = builder.mSizeProvider
//        if (mSizeProvider == null) {
//            mSizeProvider = object : SizeProvider {
//                override fun dividerSize(position: Int, parent: RecyclerView): Int {
//                    return DEFAULT_SIZE
//                }
//            }
//        }
//    }
//
//    override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
//        val adapter: RecyclerView.Adapter<*>? = parent.adapter as RecyclerView.Adapter<*>
//        adapter?:return
//        var itemCount = adapter.itemCount
//        if(parent is XRecyclerView){ //如果是XRecyclerView需要特殊处理，XRecyclerView支持添加头和尾
//            val xRecyclerView = parent as XRecyclerView
//            val len = if(xRecyclerView.isLoadingMoreEnabled()) -1 else 0
//            itemCount = xRecyclerView.getItemCount()+len
//        }
//        val lastDividerOffset = getLastDividerOffset(parent)
//
//    }
//
//    interface VisibilityProvider {
//        fun shouldHideDivider(position: Int, parent: RecyclerView): Boolean
//    }
//
//    interface PaintProvider {
//        fun dividerPaint(position: Int, parent: RecyclerView): Paint
//    }
//
//    interface ColorProvider {
//        fun dividerColor(position: Int, parent: RecyclerView): Int
//    }
//
//    interface DrawableProvider {
//        fun drawableProvider(position: Int, parent: RecyclerView): Drawable
//    }
//
//    interface SizeProvider {
//        fun dividerSize(position: Int, parent: RecyclerView): Int
//    }
//
//    class Builder(val mContext: Context) {
//        protected var mResources: Resources = mContext.resources
//        var mPaintProvider: PaintProvider? = null
//        var mColorProvider: ColorProvider? = null
//        var mDrawableProvider: DrawableProvider? = null
//        var mSizeProvider: SizeProvider? = null
//        var mVisibilityProvider: VisibilityProvider = object : VisibilityProvider {
//            override fun shouldHideDivider(position: Int, parent: RecyclerView): Boolean {
//                return false
//            }
//        }
//        var mShowLastDivider = false
//        var mPositionInsideItem = false
//        var mStartSkipCount = -1 // 默认列表第一个没有；仅仅是在使用SuperRecycleView的情况下
//
//        val mEndSkipCount = -1 // 默认列表最后一个没有；仅仅是在使用SuperRecycleView的情况下
//
//        fun checkBuilderParams() {
//            if (mPaintProvider != null) {
//                if (mColorProvider != null) {
//                    throw IllegalArgumentException(
//                        "Use setColor method of Paint class to specify line color. Do not provider ColorProvider if you set PaintProvider."
//                    );
//                }
//                if (mSizeProvider != null) {
//                    throw IllegalArgumentException(
//                        "Use setStrokeWidth method of Paint class to specify line size. Do not provider SizeProvider if you set PaintProvider."
//                    );
//                }
//            }
//        }
//    }
//}